package net.zoneland.zrdp.web.controller.system;

import net.zoneland.zrdp.common.annotation.Log;
import net.zoneland.zrdp.common.core.controller.BaseController;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.core.page.TableDataInfo;
import net.zoneland.zrdp.common.enums.BusinessType;
import net.zoneland.zrdp.common.utils.poi.ExcelProcessor;
import net.zoneland.zrdp.system.domain.SysNotifyLog;
import net.zoneland.zrdp.system.service.ISysNotifyLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 统一通知Controller
 *
 * @author zonevue
 */
@RestController
@RequestMapping("/system/notifyLog")
public class SysNotifyLogController extends BaseController {

    @Resource
    private ISysNotifyLogService notifyLogService;

    /**
     * 查询统一通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(final SysNotifyLog notifyLog) {
        startPage();
        final List<SysNotifyLog> list = notifyLogService.selectNotifyLogList(notifyLog);
        return getDataTable(list);
    }

    /**
     * 导出统一通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:export')")
    @Log(title = "统一通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(final HttpServletResponse response, final SysNotifyLog notifyLog) {
        final List<SysNotifyLog> list = notifyLogService.selectNotifyLogList(notifyLog);
        final ExcelProcessor<SysNotifyLog> util = new ExcelProcessor<>(SysNotifyLog.class);
        util.exportExcel(response, list, "统一通知数据");
    }

    /**
     * 获取统一通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") final Long id) {
        return success(notifyLogService.selectNotifyLogById(id));
    }

    /**
     * 新增统一通知
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:add')")
    @Log(title = "统一通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody final SysNotifyLog notifyLog) {
        return toAjax(notifyLogService.insertNotifyLog(notifyLog));
    }

    /**
     * 修改统一通知
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:edit')")
    @Log(title = "统一通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody final SysNotifyLog notifyLog) {
        return toAjax(notifyLogService.updateNotifyLog(notifyLog));
    }

    /**
     * 删除统一通知
     */
    @PreAuthorize("@ss.hasPermi('system:notifyLog:remove')")
    @Log(title = "统一通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable final Long[] ids) {
        return toAjax(notifyLogService.deleteNotifyLogByIds(ids));
    }
}
